package com.cloudsea.yunhaistores.controller;


import com.cloudsea.yunhaistores.dto.SessionStartDTO;
import com.cloudsea.yunhaistores.service.SessionService;
import com.cloudsea.yunhaistores.vo.SessionStartVO;
import com.cloudsea.yunhaiutils.common.ApiResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "用户-点餐会话管理", description = "用户扫码后用于开启或加入一个点餐会话")
@RestController
@RequestMapping("/sessions")
public class SessionController {

    @Autowired
    private SessionService sessionService;

    @Operation(summary = "开启点餐会话", description = "用户扫码后，小程序调用此接口。如果桌台空闲则开启新会话，如果已在使用中则加入现有会话。")
    @PostMapping("/start")
    public ApiResponse<SessionStartVO> startSession(@Valid @RequestBody SessionStartDTO dto) {
        SessionStartVO sessionInfo = sessionService.startSession(dto);
        return ApiResponse.success("会话已开启/加入", sessionInfo);
    }
}
